﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;

    public class TsysruleDB : BaseDB
    {
        public TsysruleDB(DBOperate oper) : base(oper)
        {
        }

        public bool Add(TsysruleDT detail)
        {
            int num = 0;
            string strSql = "INSERT INTO tSysRule (Name,Des) VALUES ('" + StringUtils.ToSQL(detail.Name) + "','" + StringUtils.ToSQL(detail.Des) + "')";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tSysRule where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TsysruleDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "UPDATE tSysRule set Name='", StringUtils.ToSQL(detail.Name), "',Des='", StringUtils.ToSQL(detail.Des), "' where (Sid=", detail.Sid, ")" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TsysruleDT Get(int Sid)
        {
            TsysruleDT edt = new TsysruleDT();
            try
            {
                try
                {
                    string strSql = "select * from tSysRule where (Sid=" + Sid + ")";
                    DataTable table = base.ExecuteForDataTable(strSql);
                    DataRow row = null;
                    if (table.Rows.Count >= 0)
                    {
                        row = table.Rows[0];
                        edt.Sid = Convert.ToInt32(row["Sid"]);
                        edt.Name = Convert.ToString(row["Name"]);
                        edt.Des = Convert.ToString(row["Des"]);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return edt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = "select * from tSysRule";
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

